#include "../common/common.h"
#include "rd_surface.h"

surface_t *	rd_load_surface(const char * filename)
{
	surface_t * loaded = IMG_Load(filename);
	surface_t * optimized = NULL;

	if (loaded != NULL) {
		optimized = SDL_DisplayFormatAlpha(loaded);
		SDL_FreeSurface(loaded);
	}
	if (optimized == NULL) {
		com_fatal(filename);
	}

	return optimized;
}

void rd_free_surface(surface_t * surface)
{
	SDL_FreeSurface(surface);
}

void rd_apply_surface(int x, int y, surface_t * src, surface_t * dst, rect_t* clip)
{
	rect_t offset;

	offset.x = x;
	offset.y = y;

	SDL_BlitSurface(src, clip, dst, &offset);
}


